{% extends 'base/nav.html' %}

{% block title %}修改头像 - 旅游舆情监测{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="card">
                <div class="card-header">
                    <h4 class="mb-0"><i class="fa fa-camera"></i> 修改头像</h4>
                </div>
                <div class="card-body text-center">
                    {% if messages %}
                        {% for message in messages %}
                            <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                                {{ message }}
                                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                            </div>
                        {% endfor %}
                    {% endif %}

                    <form method="post" enctype="multipart/form-data">
                        {% csrf_token %}

                        <!-- 当前头像预览 -->
                        <div class="mb-4">
                            {% if user.avatar %}
                                <img src="{{ user.avatar.url }}" alt="当前头像" class="img-thumbnail rounded-circle" style="width: 150px; height: 150px; object-fit: cover;">
                            {% else %}
                                <div class="bg-light rounded-circle d-inline-flex align-items-center justify-content-center" style="width: 150px; height: 150px;">
                                    <i class="fa fa-user fa-3x text-muted"></i>
                                </div>
                            {% endif %}
                        </div>

                        <div class="mb-3">
                            <label class="form-label">{{ form.avatar.label }}</label>
                            {{ form.avatar }}
                            {% if form.avatar.errors %}
                                <div class="text-danger small">{{ form.avatar.errors }}</div>
                            {% endif %}
                            <div class="form-text">支持 JPG, PNG 格式，建议尺寸 200x200 像素</div>
                        </div>

                        <div class="d-flex justify-content-between">
                            <a href="{% url 'users:center' %}" class="btn btn-secondary">取消</a>
                            <button type="submit" class="btn btn-primary">更新头像</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}